--[[
-- Author:      feilong
-- DateTime:    2020-10-10 17:19:33
-- Description: 节点的服务管理
    1更方便的取得节点中各服务的信息，
    2处理节点间的消息
    3开启Gate端口监听消息，client消息由watchdog处理
--]]


local skynet = require "skynet"


local MessageHandler = class("MessageHandler")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function MessageHandler:ctor()
    self:register()
end

--注册本服务里的消息
function MessageHandler:register()
    self.message_dispatch = g.dispatch

    self.message_dispatch:register('cluster_broadcast', handler(self, self.clusterBroadcast)) --给所有集群节点发消息
    self.message_dispatch:register('cluster_broadcast_res', handler(self, self.clusterBroadcastRes)) --收到集群广播

    self.message_dispatch:register('get_server', handler(self, self.getServer)) --取得指定类型的服务器节点
    self.message_dispatch:register('send_to_user', handler(self, self.sendToUser)) --
end


---------------------------------------------------------
-- CMD
---------------------------------------------------------
function MessageHandler:onStart()
    g.log:debug("manger start")



end


function MessageHandler:clusterBroadcast(msg, msg_name)
    g.log:debug("manger clusterBroadcastReq", msg, msg_name)

    return true
end

function MessageHandler:clusterBroadcastRes(from_server, msg)
    g.log:debug("manger clusterBroadcastRes")
    return true
end

function MessageHandler:getServer(server_type, uid)
    -- body
    local node = g.cluster_manager:getNodeByTypeUid(server_type, uid)
    return node
end

function MessageHandler:sendToUser(session, msg_name, msg_data, ...)
    g.message:sendService(".watchdog", "send_to_user", session, msg_name, msg_data, ...)
end


return MessageHandler